package com.yunduansing.core.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunduansing.core.commons.DbCommon;
import com.yunduansing.core.commons.DbCommon.Grid;
import com.yunduansing.core.commons.DbCommon.GridModel;
import com.yunduansing.core.commons.DbCommon.SearchModel;
import com.yunduansing.core.dao.LogDao;
import com.yunduansing.core.model.LogModel;
import com.yunduansing.core.service.LogService;
import com.yunduansing.core.utils.ResultUtil;

@Service
public class LogServiceImpl implements LogService {
	@Autowired
	private LogDao dao;

	public LogModel getByKey(Object key) {
		return dao.getByKey(key);
	}

	public ResultUtil save(LogModel entity) {
		try{
			if(entity.getId()>0)
				return ResultUtil.init(dao.update(entity)>0);
			else
				return ResultUtil.init(dao.add(entity)>0);
		}catch(Exception e){
			return ResultUtil.init(e);
		}
	}

	public ResultUtil deleteByKeys(List<Object> keys) {
		try{
			return ResultUtil.init(dao.deleteByKeys(keys)>0);
		}catch(Exception e){
			return ResultUtil.init(e);
		}
	}

	public Object pagination(Grid grid, Object search) {
		DbCommon.Pager pager=new DbCommon.Pager();
		pager.setIndex(grid.getIndex());
		pager.setData(dao.pagination(grid,search));
		pager.setRows(dao.pageCount(search));
		return pager;
	}
}
